from itpay.core.agency import agency_service
from itpay.core.mch import service as mch_service


def wrapper_name(obj):
    agency = agency_service.get_agency_by_id(obj['agency_id'])
    obj['agency'] = agency
    if agency.get('parent_id'):
        parent_agency = agency_service.get_agency_by_id(agency['parent_id'])
        agency['parent'] = parent_agency
    mch = mch_service.get_mch(obj['mch_id'])
    obj['mch'] = mch
    return obj


def wrapper_agency_info(obj):
    agency = agency_service.get_agency_by_id(obj['agency_id'])
    if agency.get('parent_id'):
        parent_agency = agency_service.get_agency_by_id(agency['parent_id'])
        agency['parent'] = parent_agency
    obj['agency'] = agency
    return obj
